package com.visionet.school.app.web.task;

import com.visionet.school.app.web.common.utils.DownLoadFileUtils;
import com.visionet.school.app.web.entity.enums.FileEnums;
import com.visionet.school.app.web.entity.file.FileClass;
import com.visionet.school.app.web.entity.file.vo.FileVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.util.concurrent.Callable;

/**
 * Created by hxpeng on 2017/4/23.
 */
public class DynamicImgTask implements Callable<FileClass> {

    private static final Logger logger = LoggerFactory.getLogger(DynamicImgTask.class);

    private String mediaId;

    private String saveFilePath;

    private Boolean thumbnail;

    public DynamicImgTask(String mediaId, String saveFilePath, Boolean thumbnail){
        this.mediaId = mediaId;
        this.saveFilePath = saveFilePath;
        this.thumbnail = thumbnail;
    }

    @Override
    public FileClass call(){
        try {
            FileClass fileClass = new FileClass();
            fileClass.setIsDeleted("0");
            FileVo fileVo =DownLoadFileUtils.downloadWechatFile(mediaId,saveFilePath,thumbnail, FileEnums.IMG.toKey());
            if(fileVo == null){
                return null;
            }else{
                BeanUtils.copyProperties(fileVo,fileClass);
            }
            return fileClass;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
